<div class="box-page-container">
  <div class="box-page-header">
    <div class="title">Группы</div>
    <div class="other-controls right">
    </div>
  </div>
  <div class="box-page-body">
    <?php if (count($this->groups) <= 0): ?>
    	<div class="box-message" id="message" style="display: block">Ни одной группы еще не создано</div>
    <?php else: ?>
    	<table class="table">
	      <thead>
	        <tr>
	          <th width="25px">ID</th>
	          <th width="80px">Ключ</th>
	          <th width="120px">Заголовок</th>
	          <th>Описание</th>
	          <th width="80px">Создано</th>
	          <th width="30px"></th>
	        </tr>
	      </thead>
	      <tbody>
	        <?php foreach ($this->groups as $group): ?>
	          <tr id="<?php echo $group->id ?>">
	            <td><?php echo $group->id ?></td>
	            <td><?php echo $group->name ?></td>
	            <td><?php echo $group->title ?></td>
	            <td><?php echo $group->description ?></td>
	            <td><?php 
	           		$date = new Zend_Date($group->created, false, Pidguin_Application::getInstance()->getLocale());
	            	echo $date->toString('dd MMMM YYYYг.');
	            ?></td>
	            <td>
	              <div class="control-bar">
	                <?php if ($group->id == 1 || $group->id == 2 || $group->id == 3 || $group->id == 4) :?>
	                <a href="/cp/group/edit?id=<?php echo $group->id ?>" title="Редактировать"><i class="icon-pencil"></i></a>
	                <?php else: ?>
	                <a href="/cp/group/edit?id=<?php echo $group->id ?>" title="Редактировать"><i class="icon-pencil"></i></a>
	                <a href="#" title="Удалить" onclick="dDelete(this); return false;"><i class="icon-trash"></i></a>
	                <?php endif; ?>
	              </div>
	            </td>
	          </tr>
	        <?php endforeach;?>
	      </tbody>
	    </table>
    <?php endif; ?>
  </div>
  <div class="box-page-footer">
    <div class="box-controls">
      <div class="right">
       	<div class="btn"><button onclick="window.location = '/cp/group/create'; return false;" class="primary">Создать группу</button></div>
      </div>
      <div id="progress" class="progress ajax-preloader-base"></div>
      <div id="control_text" class="box-controls-text"></div>
      <div class="clear-fix"></div>
    </div>
  </div>
  <div class="clear-fix"></div>
</div>
<script src="/js/jquery/jquery.js"></script>
<script>
function dDelete(el) {
	var title = $(el).parent().parent().parent().find('td').eq(2).text();
	var id = $(el).parent().parent().parent().attr('id');
	var ddel = new goog.ui.Dialog(null, true);
	// new page content
	var ddelc = '<div>Вы действительно хотите удалить группу <b>' + title + '</b>?</div>';
	ddel.setContent(ddelc);
	ddel.setTitle('Подтвердите удаление');
	ddel.setButtonSet(
		new goog.ui.Dialog.ButtonSet()
		.addButton({key: 'ok', caption: 'Да'}, true)
		.addButton({key: 'cancel', caption: 'Нет'}, false, true)
	);
	ddel.setVisible(true);
	$(ddel.getElement()).css({'width': '450px', 'left': (document.width / 2) - 225 + 'px'});
	goog.events.listen(ddel, goog.ui.Dialog.EventType.SELECT, function(e){
		if (e.key == 'ok') {
			window.location = '/cp/group/delete?id=' + id;
		}
	});
}
</script>